﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Medicalsystem.Docare.Common.Container
{
    public class ServiceLocator
    {
        private static Dictionary<Type, object> _providers = new Dictionary<Type, object>();

        public  bool Contains(Type type)
        {
            return _providers.ContainsKey(type);
        }

        public  T Get<T>()  
        {
            var type = typeof(T);

            if (Contains(type))
                return (T)_providers[type];

            return default(T); 
        }

        public  void Registe<T>(T instance)
        {
            if (instance == null)
                throw new ArgumentNullException("instance");

            var type = typeof(T);
            _providers[type] = instance;
        }
    }
}
